// JavaScript Document
var PICTURE = function(){
	var picture = function(){

	}
	picture.prototype = {
		//相册分组
		GistAll:function(arr){
			if(arr == null){
				return;
			}
			var self = this;
			var pul = self.get("pgmain");
			var frag = document.createDocumentFragment();
			for(var i=0;i<arr.length;i++){
				frag.appendChild(self.createGist(arr[i]));
			}
			pul.appendChild(frag);
		},
		GistOne:function(data){
			var self = this;
			var pul = self.get("pgmain");					
			pul.appendChild(self.createGist(data));
		},
		createGist:function(data){
			var self = this;
			var pli = self.create("li");
			var section = self.create("section");
			var image = self.create("img");
			var clear = self.create("div");
			var name = self.create("h4");
			var number = self.create("h4");
			var ispublic = self.create("h4");
			
			section.className = "pgroup cursor radiusTop radiusButtom";
			clear.className = "clear";
			name.className = "pname pinfo";
			number.className = "pnumber pinfo";
			ispublic.className = "ppublic pinfo";
			reloadPicture(image,data.image);
			//image.src = data.image;
			image.groupId = data.groupId;
			name.innerHTML = data.name;
			number.innerHTML = data.number;
			ispublic.innerHTML = data.ispublic;
			
			section.appendChild(image);
			section.appendChild(clear);
			section.appendChild(name);
			section.appendChild(number);
			section.appendChild(ispublic);
			pli.appendChild(section);
			//frag.appendChild(pli);
			
			image.onmouseover = function(){
				if(scorl == null){
					return;	
				}
				clearInterval(scorl.timer);
			}
			image.onmouseout = function(){
				if(scorl == null){
					return;	
				}	
				scorl.scrol();
			}
			image.onclick = function(){
				myajax = getByAjax();
				myajax.init(null,"get",true);
				myajax.get("/networkforum/picture/group_pictures.do?groupId="+this.groupId+"&index=0&size=10",function(data){
//					var d = eval("("+data+")");
					var d = toJson(data);
					var P = new PICTURE();
					P.MyPicture(d);
					changeHight(400);
					P = null;
					window.parent.iFrameHeight();
				});
				self.clear();
				var cp = document.getElementById("choicePicture");
				cp.innerHTML = "";
				var p = pli.cloneNode(true);
				cp.appendChild(pli.cloneNode(true));
				
				//添加scroll事件
				var param = {
					url:"/networkforum/picture/group_pictures.do",
					size:20,
					callBack:scrollBack,
					target:window.parent,
					containerId:"inner",
					data:{groupId:this.groupId}
				}
				page.scrolls(param);
			}
			return pli;
		},
		//图片详细信息
		MyPicture:function(arr){
			var FONT = function(){
				var font = function(){
					this.alpha = null;
					this.header = null;
					this.footer = null;
					this.left = null;
					this.top = null;
					this.width = null;
					this.height = null;
				}
				font.prototype = {
					init:function(left,top,width,height){
						var self = this;
						self.left = left;
						self.top = top;
						self.width = width;
						self.height = height;
					},
					Alpha:function(){
						var self = this;
						self.alpha = self.create("section");
						with(self.alpha.style){
							left = self.left + "px";
							top = self.top + "px";
							width = self.width + "px";
							height = self.height + "px";
						}
						self.alpha.className = "pictureAlpha alpha";
						
						return self.alpha;
					},
					Header:function(){
						var self = this;
						self.header = self.create("section");
						self.header.className = "pictureHeader";
						with(self.header.style){
							left = self.left + 15 + "px";
							top = self.top + 15 + "px";
						}
						
						var downLoad = self.create("label");
						downLoad.innerHTML = "下载";
						self.header.appendChild(downLoad);
						
						return self.header;
					},
					Footer:function(publishTime,replyTime){
						var self = this;
						self.footer = self.create("section");
						self.footer.className = "pictureFooter";
						with(self.footer.style){
							left = self.left + 5 + "px";
							top = self.height - 5 + "px";
							width = self.width*0.95 + "px";
						}
						
						self.footer.innerHTML = 
								"<h4 class='publishTime picutreInfo'>上传时间:"+publishTime+"</h4>" +
								"<h4 class='replyTime picutreInfo'>评论次数:"+replyTime+"</h4>";
						
						return self.footer;
					},
					create:function(tagName){
						return document.createElement(tagName);
					}
				}
				return new font();
			}();
			if(!(arr instanceof Array)){
				return;
			}
			var self = this;
			var leftFrag = document.createDocumentFragment();
			var middleFrag = document.createDocumentFragment();
			var rightFrag = document.createDocumentFragment();
			var lh = 0;
			var mh = 0;
			var rh = 0;
			for(var i =0;i<arr.length;i++){
				var data = arr[i];
				var li = self.create("li");
				li.className = "innerLi";
				var image = self.create("img");
				image.className = "innerImage";
				image.publishTime = data.publishTime;
				image.visitTime = data.visitTime;
				image.replyTime = data.replyTime;
				//image.src = data.pictureSrc;
				reloadPicture(image,data.pictureSrc);
				image.index = i;
				li.appendChild(image);
				if(lh<=mh&&lh<=rh){
					leftFrag.appendChild(li);
					lh = lh + data.height;
				}
				else if(mh<lh&&mh<=rh){
					middleFrag.appendChild(li);
					mh = mh + data.height;
				}
				else if(rh<mh&&rh<lh){
					rightFrag.appendChild(li);
					rh = rh + data.height;
				}
				image.onmouseover = function(ev){
					ev = ev || window.event;
					var node = ev.target.tagName == "IMG"?ev.target:ev.target.children[0];
					
					node.className = "innerImage alpha8";
					with(node.style){
						cursor = "pointer";
					}
					var parent = node.parentElement;
					//添加过滤层
					FONT.init(node.offsetLeft,node.offsetTop,node.offsetWidth,node.offsetHeight);
					var footer = FONT.Footer(node.publishTime,node.replyTime);
					parent.appendChild(footer);
					parent.footer = footer;
				}
				image.onmouseout = function(ev){
					ev = ev || window.event;
					var node = ev.target;
					node.className = "innerImage";
					var parent = node.parentElement;
					parent.removeChild(parent.footer);
					parent.footer = null;
				}
			}
			var left = self.get("leftinner");
			var middle = self.get("middleinner");
			var right = self.get("rightinner");
			left.appendChild(leftFrag);
			middle.appendChild(middleFrag);
			right.appendChild(rightFrag);
			if(window.parent.iFrameHeight){
				window.parent.iFrameHeight();
			}
		},
		//好友图片展示
		FirendPicture:function(arr){
			if(!(arr instanceof Array)){
				return;
			}
			var self = this;
			var leftFrag = document.createDocumentFragment();
			var middleFrag = document.createDocumentFragment();
			var rightFrag = document.createDocumentFragment();
			var lh = 0;
			var mh = 0;
			var rh = 0;
			for(var i =0;i<arr.length;i++){
				var data = arr[i];
				var li = self.create("li");
				li.className = "innerLi";
				var image = self.create("img");
				image.className = "innerImage";
				image.publishTime = data.publishTime;
				image.visitTime = data.visitTime;
				image.replyTime = data.replyTime;
				//image.src = data.pictureSrc;
				reloadPicture(image,data.pictureSrc);
				image.index = i;
				li.appendChild(image);
				if(lh<=mh&&lh<=rh){
					leftFrag.appendChild(li);
					lh = lh + data.height;
				}
				else if(mh<lh&&mh<=rh){
					middleFrag.appendChild(li);
					mh = mh + data.height;
				}
				else if(rh<mh&&rh<lh){
					rightFrag.appendChild(li);
					rh = rh + data.height;
				}
			}
			var left = self.get("leftinner");
			var middle = self.get("middleinner");
			var right = self.get("rightinner");
			left.appendChild(leftFrag);
			middle.appendChild(middleFrag);
			right.appendChild(rightFrag);
		},
		//最新图片
		LastPicture:function(){
			
		},
		//提供一个便捷的方法获取界面元素
		get:function(cid){
			return document.getElementById(cid);	
		},
		create:function(tagName){
			return document.createElement(tagName);
		},
		clear:function(){
			var leftinner = document.getElementById("leftinner");
			var middleinner = document.getElementById("middleinner");
			var rightinner = document.getElementById("rightinner");
			var pictureNav = document.getElementById("pictureNav");
			
			leftinner.innerHTML = null;
			middleinner.innerHTML = null;
			rightinner.innerHTML = null;
			
			leftinner.appendChild(pictureNav);
		}
	}
	return picture;
}();
/*******************创建相册********************/
function groupHandle(dis){
	var group = document.getElementById("addGroup");
	group.style.display = dis;
}


var scorl = null;

function scorllHandle(distance){
	if(scorl == null){
		alert("多建几个相册试试！");
		return;
	}
	scorl.mvoeTo(distance);
}

function alphaHandle(ev){
	ev = ev || window.event;
	ev.target.style.display = "none";
}
function changeHight(height){
	var height = document.getElementById("pginner").offsetHeight;
	var frame = this.frameElement;
	frame.style.height = frame.offsetHeight+ height + 500 +"px";
}